package com.itcast.spark.baseDataStruct

import org.apache.spark.mllib.linalg
import org.apache.spark.mllib.linalg.Vectors
import org.apache.spark.mllib.linalg.distributed.RowMatrix
import org.apache.spark.rdd.RDD
import org.apache.spark.sql.SparkSession
import org.apache.spark.{SparkConf, SparkContext}

/**
 * DESC:
 */
object _06RowMatix {
  def main(args: Array[String]): Unit = {
    val conf: SparkConf = new SparkConf().setAppName("_04libsvmSparkSQL").setMaster("local[*]")
    val spark: SparkSession = SparkSession.builder().config(conf).getOrCreate()
    val sc: SparkContext = spark.sparkContext
    val path = "D:\\BigData\\Workspace\\spark_learaning_2.11\\spark-study-day07_2.11\\src\\main\\resources\\RowMatrix.txt"
    //如何读取vector的类型的数据转化为RDD[Vector]
    val data: RDD[linalg.Vector] = sc.textFile(path).map(_.split(" ").map(_.toDouble)).map(x => Vectors.dense(x))
    //增加分布式特性
    val rowMatrix = new RowMatrix(data) //RDD[Vector]
    println(rowMatrix)
    println(rowMatrix.numRows())
    println(rowMatrix.numCols())
  }
}
